package de.tabuma.formcreator.logik;

import de.tabuma.formcreator.formstructur.logik.FormStrukturFacade;
import de.tabuma.formcreator.formstructur.logik.FormStrukturFactory;
import de.tabuma.formcreator.entity.*;
import de.tabuma.soap.entity.wsdl.*;

import java.util.logging.*;
import java.util.*;

/**
  * @author $Author: $
  * @version $Revision: $
  * @since $Date: $
 */
public class FormManagerFactory {

    private static final Logger log = Logger.getLogger(FormManagerFactory.class.getName());

    public static FormManager createFormularManager(TDefinitions wsdl,String operation) {

        log.fine("start creating formular mananger");
        long startTime = Calendar.getInstance().getTimeInMillis();
        FormManager formularManager = new FormManager(true,operation);


        //first step loading of request object
        FormStructur requestStruktur = FormStrukturFactory.createFormularStrukturAsRequestObjekt(wsdl,operation);
        log.fine("finishing creating request object at "+(Calendar.getInstance().getTimeInMillis() - startTime));
        log.fine("Struktur ohne remove");
        List<FormStructur> fS = requestStruktur.getFormularStrukturList();
        for(int i=0;i<fS.size();i++) {
            log.fine("s:"+fS.get(i).getName());
        }
        FormStrukturFacade.createFormStructurWithoutChoiceAllSequence(requestStruktur,formularManager);
        
        log.fine("Struktur mit remove");
        fS = requestStruktur.getFormularStrukturList();
        for(int i=0;i<fS.size();i++) {
            log.fine("s:"+fS.get(i).getName());
        }
        log.fine("finishing removing structurs at "+(Calendar.getInstance().getTimeInMillis() - startTime));
        formularManager.setRequestObject(requestStruktur);

        //second step loading of response object
        FormStructur responseStructur = FormStrukturFactory.createFormularStrukturAsResponseObjekt(wsdl,operation);
        FormStrukturFacade.createFormStructurWithoutChoiceAllSequence(responseStructur,formularManager);
        formularManager.setResponseObject(responseStructur);

        FormStructur faultStructur = FormStrukturFactory.createFormularStrukturAsDefaultOjbect(wsdl, operation);
        if(faultStructur!=null) {
            FormStrukturFacade.createFormStructurWithoutChoiceAllSequence(faultStructur,formularManager);
        }
        formularManager.setFaultObject(faultStructur);

        //FormularStruktur formularStruktur1 = FormularStrukturFactory.c;
        return formularManager;
    }

}